package cn.kgc.crowdfundingadmin.controller;


import cn.kgc.crowdfundingadmin.common.ResultEntity;
import cn.kgc.crowdfundingadmin.pojo.Cert;
import cn.kgc.crowdfundingadmin.pojo.Role;
import cn.kgc.crowdfundingadmin.service.CertService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class CertController {
    @Resource
    CertService certService;

    @RequestMapping("/cert/search/by/keyword")
    public ResultEntity<PageInfo<Cert>> search(
            @RequestParam(value="pageNum", defaultValue="1",required = false) Integer pageNum,
            @RequestParam(value="pageSize", defaultValue="5",required = false) Integer pageSize,
            @RequestParam(value="keyword", defaultValue="",required = false) String keyword
    ) {
        //查询的到pageInfo对象
        PageInfo<Cert> pageInfo=certService.queryForKeywordWithPage(pageNum,pageSize,keyword);
        //返回封装结果
        return ResultEntity.successWithoutData(pageInfo);
    }
    //根据id查询
    @RequestMapping("/cert/get/list/by/id/list")
    public ResultEntity<List<Cert>> getRoleListByIdList(@RequestBody List<Integer> certIdList) {
        List<Cert> list=certService.getCertListByIdList(certIdList);
        return ResultEntity.successWithoutData(list);

    }

    //删除
    @RequestMapping("/cert/batch/remove")
    public ResultEntity<String> batchRemove(@RequestBody List<Integer> certIdList) {
            certService.batchRemove(certIdList);
            return ResultEntity.successWithoutData();
    }

    //增加
    @RequestMapping("/cert/save/cert")
    public ResultEntity<String> saveRole(@RequestParam("certName") String certName) {
    certService.saveRole(certName);
    return ResultEntity.successWithoutData();
    }

    //更新
    @RequestMapping("/cert/update/cert")
    public ResultEntity<String> updateRole(Cert cert) {
        certService.updateRole(cert);
        return ResultEntity.successWithoutData();
    }
    }


